﻿using System;
using System.Configuration;
using System.Globalization;

namespace Aquarinum.WebSocket.Server.WinService
{
    public class ConfigManagerHelper
    {
        /// <summary>
        /// 获取配置
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="configkey">配置的key（配置项）</param>
        /// <returns></returns>
        public static T Get<T>(string configkey)
        {
            try
            {
                string value = ConfigurationManager.AppSettings[configkey];

                if (string.IsNullOrEmpty(value))
                {
                    throw new Exception(string.Format("未找到当前配置项,请联系管理员添加.key:{0}", configkey));
                }

                return (T)Convert.ChangeType(value, typeof(T), CultureInfo.InvariantCulture);
            }
            catch (Exception exp)
            {

               
                throw exp;
            }
        }

    }
}
